/**
  ETFRoot project, Anyang Normal University && IMP-CAS
  \class ETFTaLTracker
  \brief trackers for tracking with 2 DCTaL DCs
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2022-04-25
  \date 2021-04-25 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date         <th>Author      <th>Description                   </tr>
  <tr>  <td>2021-04-25   <td>Asia Sun    <td>file created                  </tr>
  </table>

  \copyright Copyright (c) 2021 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#include "ETFTaLTracker.h"
#include "ETFDetectorManager.h"
#include "ETFParaManager.h"
#include "ETFYaml.h"
#include "ETFDCTaL.h"
#include "ETFMath.h"
#include "ETFTrackTa.h"
#include "ETFTimer.h"
#include "ETFMsg.h"

ClassImp(ETFTaLTracker);

ETFTaLTracker::ETFTaLTracker(const char *name, const vector<string> &dcs, const char *t0)
: ETFTaTracker(name){
  if(!strcmp(name, "")) return;

  ETFDetectorManager *m = ETFDetectorManager::Instance();
  for(const string &dc : dcs) fDCs.push_back(dynamic_cast<ETFVDC *>(m->GetDetector(dc.c_str())));
  fTimer = dynamic_cast<ETFTimer *>(m->GetDetector(t0));

  ETFParaManager *pm = ETFParaManager::Instance();
  const YAML::Node &d2PDConfig = (*pm->GetMisPara())["D2THREPDTaL"];
  if(d2PDConfig) D2THREPD = d2PDConfig.as<double>();
  const YAML::Node &chiPDConfig = (*pm->GetMisPara())["chiPDTaL"];
  if(chiPDConfig) fChiPD = chiPDConfig.as<double>();
} // end ctor

ETFTaLTracker::~ETFTaLTracker(){}

///< if accept the layer or not in Map()
bool ETFTaLTracker::GoodLayer(ETFVDC *dc, DCType type, int x12) const{
  if(!dc) ETFMsg::Error("ETFTaLTracker", "GoodLayer: null dc pointer.");

  const int mul = dc->Multi(type, fNLayer%2);
  // if(mul > 0.5*dc->GetNL()) return false;
  if(mul > 3) return false;
  return true;
} // end member function GoodLayer

bool ETFTaLTracker::SetDriftDistance(ETFVTrack *trk){
  return fDCs[0]->SetDriftDistance(trk);
} // end member function SetDriftDistance
